package com.prp.gwt.client.widgets.user.php;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.prp.gwt.client.user.article.ArticleHistoryHandler;
import com.prp.gwt.client.vo.SubjectRecommend;

public class RecentRecommendItem extends VerticalPanel {

	public RecentRecommendItem(final SubjectRecommend sr) {
		addStyleName("recentRecommend-item");
		{
			HorizontalPanel hPanel = new HorizontalPanel();
			HTML title = new HTML("<a>" + sr.getTitle() + "</a>");
			title.addClickHandler(new ClickHandler() {
				@Override
				public void onClick(ClickEvent event) {
					History.newItem(ArticleHistoryHandler.PREFIX_RECOMMEND
							+ sr.getId());
				}
			});
			hPanel.add(title);
			title.addStyleName("recentRecommend-item-title");
			Label label = new Label("-");
			label.addStyleName("recentRecommend-item-text");
			hPanel.add(label);
			HTML entity = new HTML("<a>" + sr.getEntityName() + "</a>");
			entity.addStyleName("recentRecommend-item-entity");
			hPanel.add(entity);
			add(hPanel);
		}
		HTML content = new HTML(sr.getContent() + "<a>(阅读)</a>");
		content.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				History.newItem(ArticleHistoryHandler.PREFIX_RECOMMEND
						+ sr.getId());
			}
		});
		add(content);
		content.addStyleName("recentRecommend-item-content");
		{
			Label label = new Label(sr.getDate() + "  (评论:" + sr.getReplyNum()
					+ "/" + sr.getClickFreq() + ")");
			add(label);
			setCellHorizontalAlignment(label, ALIGN_RIGHT);
			label.addStyleName("recentRecommend-item-footer");
		}
	}

}
